package com.fsnbigdata.domain;
import javax.persistence.OrderBy;

import org.hibernate.validator.constraints.Length;
import org.springframework.roo.addon.javabean.annotations.RooEquals;
import org.springframework.roo.addon.javabean.annotations.RooJavaBean;
import org.springframework.roo.addon.javabean.annotations.RooToString;
import org.springframework.roo.addon.jpa.annotations.entity.RooJpaEntity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Version;
import io.springlets.format.EntityFormat;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.OneToMany;
import org.springframework.roo.addon.jpa.annotations.entity.JpaRelationType;
import org.springframework.roo.addon.jpa.annotations.entity.RooJpaRelation;
import java.util.Objects;
import javax.persistence.Entity;
import javax.validation.Valid;

import org.springframework.util.Assert;

/**
 * = ListQuadrat
 *
 * TODO Auto-generated class documentation
 *
 */
@RooJavaBean
@RooToString
@RooJpaEntity
@RooEquals(isJpaEntity = true)
@Entity
@EntityFormat
public class ListQuadrat {

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    @Version
    private Integer version;

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    @ManyToOne(fetch = FetchType.EAGER)
    @EntityFormat
    private Vegetation vegetation;

    /**
     * 年份
     */
    @Length(min = 0,max = 255,message = "植被年份长度必须为0-255")
    private String quadratYear;

    /**
     * 调查人
     */
    @Length(min = 0,max = 255,message = "植被年份长度必须为0-255")
    private String investigator;

    /**
     * 地点
     */
    @Length(min = 0,max = 255,message = "植被地点长度必须为0-255")
    private String location;

    /**
     * 坐标
     */
    @Length(min = 0,max = 255,message = "植被坐标长度必须为0-255")
    private String coordinate;

    /**
     * 海拔
     */
    @Length(min = 0,max = 255,message = "植被海拔长度必须为0-255")
    private String altitude;

    /**
     * 坡度
     */
    @Length(min = 0,max = 255,message = "植被坡度长度必须为0-255")
    private String gradient;

    /**
     * 坡向
     */
    @Length(min = 0,max = 255,message = "植被坡向长度必须为0-255")
    private String exposure;

    /**
     * 乔木层样本面积
     */
    @Length(min = 0,max = 255,message = "植被乔木层样本面积长度必须为0-255")
    private String treeLayerArea;

    /**
     * 乔木层覆盖度
     */
    @Length(min = 0,max = 255,message = "植被乔木层覆盖度长度必须为0-255")
    private String treeLayerCoverage;

    /**
     * 灌木层样本覆盖度
     */
    @Length(min = 0,max = 255,message = "植被灌木层样本覆盖度长度必须为0-255")
    private String shrubLayerArea;

    /**
     * 灌木层覆盖度
     */
    @Length(min = 0,max = 255,message = "植被灌木层覆盖度长度必须为0-255")
    private String shrubLayerCoverage;

    /**
     * 草本层覆盖度
     */
    @Length(min = 0,max = 255,message = "植被草本层覆盖度长度必须为0-255")
    private String fieldLayerArea;

    /**
     * 草本层覆盖度
     */
    @Length(min = 0,max = 255,message = "植被草本层覆盖度长度必须为0-255")
    private String fieldLayerCoverage;

    /**
     * 样方表
     */
    @OneToMany(cascade = { javax.persistence.CascadeType.ALL }, fetch = FetchType.EAGER, mappedBy = "listQuadrat", orphanRemoval = true)
    @RooJpaRelation(type = JpaRelationType.COMPOSITION)
    @OrderBy("id")
    @Valid
    private Set<ListQuadratItem> items = new HashSet<ListQuadratItem>();

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE = "The given Iterable of items to add can't be null!";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE = "The given Iterable of items to add can't be null!";

    /**
     * This `equals` implementation is specific for JPA entities and uses
     * the entity identifier for it, following the article in
     * https://vladmihalcea.com/2016/06/06/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
     *
     * @param obj
     * @return Boolean
     */
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        // instanceof is false if the instance is null
        if (!(obj instanceof ListQuadrat)) {
            return false;
        }
        return getId() != null && Objects.equals(getId(), ((ListQuadrat) obj).getId());
    }

    /**
     * This `hashCode` implementation is specific for JPA entities and uses a fixed `int` value to be able
     * to identify the entity in collections after a new id is assigned to the entity, following the article in
     * https://vladmihalcea.com/2016/06/06/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
     *
     * @return Integer
     */
    public int hashCode() {
        return 31;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return Long
     */
    public Long getId() {
        return this.id;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param id
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return Integer
     */
    public Integer getVersion() {
        return this.version;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param version
     */
    public void setVersion(Integer version) {
        this.version = version;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return Vegetation
     */
    public Vegetation getVegetation() {
        return this.vegetation;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param vegetation
     */
    public void setVegetation(Vegetation vegetation) {
        this.vegetation = vegetation;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getQuadratYear() {
        return this.quadratYear;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param quadratYear
     */
    public void setQuadratYear(String quadratYear) {
        this.quadratYear = quadratYear;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getInvestigator() {
        return this.investigator;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param investigator
     */
    public void setInvestigator(String investigator) {
        this.investigator = investigator;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getLocation() {
        return this.location;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param location
     */
    public void setLocation(String location) {
        this.location = location;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getCoordinate() {
        return this.coordinate;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param coordinate
     */
    public void setCoordinate(String coordinate) {
        this.coordinate = coordinate;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getAltitude() {
        return this.altitude;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param altitude
     */
    public void setAltitude(String altitude) {
        this.altitude = altitude;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getGradient() {
        return this.gradient;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param gradient
     */
    public void setGradient(String gradient) {
        this.gradient = gradient;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getExposure() {
        return this.exposure;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param exposure
     */
    public void setExposure(String exposure) {
        this.exposure = exposure;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getTreeLayerArea() {
        return this.treeLayerArea;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param treeLayerArea
     */
    public void setTreeLayerArea(String treeLayerArea) {
        this.treeLayerArea = treeLayerArea;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getTreeLayerCoverage() {
        return this.treeLayerCoverage;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param treeLayerCoverage
     */
    public void setTreeLayerCoverage(String treeLayerCoverage) {
        this.treeLayerCoverage = treeLayerCoverage;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getShrubLayerArea() {
        return this.shrubLayerArea;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param shrubLayerArea
     */
    public void setShrubLayerArea(String shrubLayerArea) {
        this.shrubLayerArea = shrubLayerArea;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getShrubLayerCoverage() {
        return this.shrubLayerCoverage;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param shrubLayerCoverage
     */
    public void setShrubLayerCoverage(String shrubLayerCoverage) {
        this.shrubLayerCoverage = shrubLayerCoverage;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getFieldLayerArea() {
        return this.fieldLayerArea;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param fieldLayerArea
     */
    public void setFieldLayerArea(String fieldLayerArea) {
        this.fieldLayerArea = fieldLayerArea;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getFieldLayerCoverage() {
        return this.fieldLayerCoverage;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param fieldLayerCoverage
     */
    public void setFieldLayerCoverage(String fieldLayerCoverage) {
        this.fieldLayerCoverage = fieldLayerCoverage;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return Set
     */
    public Set<ListQuadratItem> getItems() {
        return this.items;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param items
     */
    public void setItems(Set<ListQuadratItem> items) {
        this.items = items;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String toString() {
        return "ListQuadrat {" + "id='" + id + '\'' + ", version='" + version + '\'' + ", quadratYear='" + quadratYear + '\'' + ", investigator='" + investigator + '\'' + ", location='" + location + '\'' + ", coordinate='" + coordinate + '\'' + ", altitude='" + altitude + '\'' + ", gradient='" + gradient + '\'' + ", exposure='" + exposure + '\'' + ", treeLayerArea='" + treeLayerArea + '\'' + ", treeLayerCoverage='" + treeLayerCoverage + '\'' + ", shrubLayerArea='" + shrubLayerArea + '\'' + ", shrubLayerCoverage='" + shrubLayerCoverage + '\'' + ", fieldLayerArea='" + fieldLayerArea + '\'' + ", fieldLayerCoverage='" + fieldLayerCoverage + '\'' + ", ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE='" + ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE + '\'' + ", ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE='" + ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE + '\'' + "}" + super.toString();
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param itemsToAdd
     */
    public void addToItems(Iterable<ListQuadratItem> itemsToAdd) {
        Assert.notNull(itemsToAdd, ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE);
        for (ListQuadratItem item : itemsToAdd) {
            this.items.add(item);
            item.setListQuadrat(this);
        }
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param itemsToRemove
     */
    public void removeFromItems(Iterable<ListQuadratItem> itemsToRemove) {
        Assert.notNull(itemsToRemove, ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE);
        for (ListQuadratItem item : itemsToRemove) {
            this.items.remove(item);
            item.setListQuadrat(null);
        }
    }
}
